<%@ taglib prefix="spring-tags" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="spring-form" uri="http://www.springframework.org/tags/form"%>
<%@ page
    import="org.jiscinvolve.astrodabis.mallow.model.api.Tag"
    import="org.jiscinvolve.astrodabis.mallow.model.api.Query"
    import="org.jiscinvolve.astrodabis.mallow.model.api.QueryTag"
    import="org.jiscinvolve.astrodabis.mallow.model.api.Result"
    import="org.jiscinvolve.astrodabis.mallow.model.api.Account"
    import="org.jiscinvolve.astrodabis.mallow.model.tap.TapTable"
    import="org.jiscinvolve.astrodabis.mallow.model.tap.TapService"
    import="org.jiscinvolve.astrodabis.mallow.control.ViewData"
    session="true"
%>
<%@ include file="/jsp/init.jsp" %>
<%@ include file="/jsp/queries/init.jsp" %>
<html>
    <head>
	    <title>AstroDAbis query <%= query.name() %></title>
        <link href='/astrodabis/css/page.css' rel='stylesheet' type='text/css'/>
    </head>
    <body>
        <%@ include file="/jsp/header.jsp" %>
        <div class='body'>
            <div class='left'>
                <%@ include file="/jsp/menu.jsp" %>
            </div>
            <div class='right'>
                <a href='<%= data.path(query) %>'>
                    <img src='<%= data.qrcode(data.path(query)) %>'/>
                </a>
            </div>
            <div class='content'>
        	    <h2><%= query.owner().name() %>&apos;s query <%= query.name() %></h2>

      			<spring-form:errors path="bean"/>
	            <spring-form:form method="post" modelAttribute="bean">

              		<spring-form:hidden path="table"/>

                    <fieldset>
                        <legend>Query details</legend>
                        <div>
                            <ul>
                                <li>
		                      		Name : <spring-form:input  path="name"/>
	                      			<spring-form:errors path="name"/>
                                </li>
                                <li>
                                    Created : <%= query.created() %>
                                </li>
                                <li>
                                    Owner : <a href='<%= data.path(query.owner()) %>'><%= query.owner().name() %></a>
                                </li>
                                <li>
                                    Service : <a href='<%= data.path(query.table().service()) %>'><%= query.table().service().name() %></a>
                                </li>
                                <li>
                                    Table : <a href='<%= data.path(query.table()) %>'><%= query.table().name() %></a>
                                </li>
                                <li>
                                    Status : <%= query.status() %>
                                </li>
                            </ul>
                        </div>
                    </fieldset>
                    <fieldset>
                        <legend>Description</legend>
                        <div>
		              		<spring-form:textarea rows='3' cols='50' path="text"/>
	              			<spring-form:errors path="text"/>
                        </div>
                    </fieldset>

                    <fieldset>
                        <legend>ADQL query</legend>
                        <div>
                            <%= query.head() %>
                        </div>
                        <div>
		              		<spring-form:textarea rows='3' cols='50' path="where"/>
	              			<spring-form:errors path="where"/>
                        </div>
                        <div>
                            <%= query.tail() %>
                        </div>
                    </fieldset>

			        <div>
			            <button name="save"   type="submit">Save</button>
			            <button name="run"    type="submit">Run</button>
			            <button name="clone"  type="submit">Clone</button>
		            </div>

    		    </spring-form:form>

            </div>
        </div>
        <%@ include file="/jsp/footer.jsp" %>
    </body>
</html>

